Question: How do I used Event Handler to trigger next step in Class C ( // do something ) that is dependent on Status Update without relying on a Thread.Sleep... ??
Disclaimer: Consider me a novice programmer. Consider this my best attempt and a fairly non-elegant solution. Please feel free to re-design and re-code, this should be considered as only one prototype effort to solve above issue.
NOTE: Code Exampled Edited for 'real - world' example that should actually work. ( not fully tested )
Additional Question - Thread.Sleep(400) in example below stops main thread... halting all processes, although looking for an alternative, is this even a viable solution??
public class OrderA : ICurrencyOrder
{
private int _clid;
private string _status;
public int Clid
{
get { return _clid; }
set { _clid = value; }
}
public string Status
{
get { return _status; }
set { _status = value; }
}
}
Class B
{
// event delegate for UpdateOrder
public event UpdateOrderDelegate UpdateOrderEvent;
/* Code Here to receive and process order assign status etc */
/* An Event Arguments (args) Class is created that hold e.Status and e.Clid values */
Pravesh Singh
10-Aug-2013Hello!
I think that AutoResetEvent(http://msdn.microsoft.com/en-us/library/system.threading.autoresetevent.aspx) is the class you are looking for if you want to wait for something to happen before continuing doing something else.
There is an example provided at the class description page, basically you call WaitOne where you want to wait, and Set when you want to continue.